<?php include $this->templateDir . 'common/header.php'; ?>
<body style="padding: 10px;">
<style>
    .headers span{background: #009688;margin-left: 30px;padding: 10px;color: #ffffff;}
    .headers button{float: right;margin-top: -5px;}
    .headers div{border-bottom: solid 2px #009688;margin-top: 8px;}
</style>
<div class="yadmin-body animated fadeIn">
    <input type="hidden" name="pid" id="pid" value="<?php echo $this->data['pid'];?>">
    <div class="headers">
        <span>菜单列表</span>
        <button class="layui-btn layui-btn-xs" onclick="add()">添加</button>
        <div></div>
    </div>
    <?php if($this->data['pid']>0){?>
        <button class="layui-btn layui-btn-primary layui-btn-sm" style="float: right;margin-top: 5px;margin-bottom: 5px;" onclick="backs(<?php echo $this->data['backid']?>)">返回上级菜单</button>
    <?php }?>
    <table class="layui-table">
        <thead>
        <tr>
            <th style="width: 80px;min-width:80px;">排序</th>
            <th style="width: 80px;min-width:80px;">菜单ID</th>
            <th style="min-width: 200px"><?php if($this->data['pid']>0){echo "【子】";}else{echo '【主】';}?> 菜单名称</th>
            <th style="min-width: 100px;">控制器</th>
            <th style="min-width: 100px;">方法名</th>
            <th style="width: 90px;min-width:90px;">是否隐藏</th>
            <th style="width: 90px;min-width:90px;">状态</th>
            <th style="width: 150px;min-width: 150px;">操作</th>
        </tr>
        </thead>
        <tbody>
        <?php
        if(!$this->data['list']){
            echo "<tr><td colspan='8' style='text-align: center;color: red'>无数据</td></tr>";
        }
        ?>
        <?php foreach ($this->data['list'] as $k => $v) { ?>

            <tr>
                <td><?php echo $v['ord']?></td>
                <td><?php echo $v['mid']?></td>
                <td><?php echo $v['title']?></td>
                <td><?php echo $v['controller']?></td>
                <td><?php echo $v['method']?></td>
                <td><?php echo $v['ishidden']==1?"隐藏":"显示";?></td>
                <td><?php echo $v['status']==1?"<span style='color: red'>禁用</span>":"<span style='color: #009688'>正常</span>";?></td>
                <td>
                    <button class="layui-btn layui-btn-xs " onclick="childs(<?php echo $v['mid']?>)">子菜单</button>
                    <button class="layui-btn layui-btn-warm layui-btn-xs" onclick="edit(<?php echo $v['mid']?>)">编辑</button>
                    <button class="layui-btn layui-btn-xs layui-btn-danger" onclick="del(<?php echo $v['mid']?>)">删除</button>
                </td>
            </tr>
        <?php } ?>
        </tbody>
    </table>
</div>
</body>
</html>
<script>
    layui.use(['layer'],function(){
        layer = layui.layer;
        $ = layui.jquery;
    });
    //添加
    function add() {
        var pid  = $("#pid").val();
        layer.open({
            type:2,
            title: "添加菜单",
            shade:0.3,
            area:['480px','450px'],   // 判断是否是子菜单
            content:"<?php echo  PG_SROOT.'menu/add/';?>"+pid
        });
    }

    //添加
    function edit(mid) {
        var pid  = $("#pid").val();
        layer.open({
            type:2,
            title: "编辑菜单",
            shade:0.3,
            area:['480px','450px'],   // 编辑还是添加 / pid
            content:"<?php echo  PG_SROOT.'menu/edit/';?>"+mid+'/'+pid
        });
    }

    //删除
    function del(mid) {
        layer.confirm('确定要删除吗？',{
            icon:3,
            btn:['确定','取消']
        },function(){
            var delurl = "<?php echo u('menu','del');?>";
            $.post(delurl,{mid:mid},function (res) {
                if(res.status=="ok"){
                    layer.msg(res.data,{'icon':1});
                    setTimeout(function(){window.location.reload();},1000);
                }else{
                    layer.msg(res.data,{'icon':2});
                }
            },"json");
        });
    }

    //子菜单
    function childs(mid) {
        window.location.href ="<?php echo PG_SROOT.'menu/index/';?>"+mid
    }

    // 返回上级菜单
    function backs(pid){
        window.location.href = "<?php echo PG_SROOT.'menu/index/';?>"+pid;
    }
</script>